// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Death Egg Robot Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 46 : TYPE_DEATHEGGROBOT

// Function declarations
reserve function DeathEggRobot_Function101
reserve function DeathEggRobot_Function102
reserve function DeathEggRobot_Function103
reserve function DeathEggRobot_Function104

// Static Values

// Tables
private table DeathEggRobot_table55
	8, 9, 10, 9
end table

private table DeathEggRobot_table46
	0, 0, 1, 2, 3, -1, 0
end table

private table DeathEggRobot_table47
	0, 5, 6, 7, 8, -1, 0
end table

private table DeathEggRobot_table48
	0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 192
end table

private table DeathEggRobot_table52
	0, 0, 0, 0, 0, 0, 0, 0, 0
end table

private table DeathEggRobot_table49
	0, 0, 1, 2, 192
end table

private table DeathEggRobot_table53
	0, 0, 0
end table

private table DeathEggRobot_table50
	0, 0, 1, 2, 3, 64, 4, 5, 6, 7, 8, 64, 9, 10, 1, 2
	3, 64, 4, 5, 6, 7, 8, 64, 192
end table

private table DeathEggRobot_table51
	0, 136, 135, 134, 133, 11, 64, 192
end table

private table DeathEggRobot_table54
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
end table

private table DeathEggRobot_table60
	0, 8, 0, 0, 0
end table

private table DeathEggRobot_table56
	0, 16, 0, 0, 0
end table

private table DeathEggRobot_table0
	6, 4, -0x40000, 0x3C0000, 3, -0xC0000, 0x80000, 2, 0xC0000, -0x80000, 1, 0x40000, 0x240000, -1, -0x40000, 0x3C0000, -2, -0xC0000, 0x80000, -3, 0x40000, 0x240000
end table

private table DeathEggRobot_table1
	5, 8, 0, -0x2000, 0xC00, 3, -0x2000, 0xC00, 2, -0x2000, 0xC00, -2, -0x2000, 0xC00, 1, -0x800, 0x400, -3, -0x800, 0x400
end table

private table DeathEggRobot_table2
	5, 8, 0, -0x1400, 0x1400, 3, -0x1400, 0x1400, 2, -0x1400, 0x1400, -2, -0x1400, 0x1400, 1, -0x600, 0x600, -3, -0x600, 0x600
end table

private table DeathEggRobot_table3
	5, 8, 0, -0x800, 0x1400, 3, -0x800, 0x1400, 2, -0x800, 0x1400, -2, -0x800, 0x1400, 1, -512, 0x400, -3, -512, 0x400
end table

private table DeathEggRobot_table4
	5, 8, 0, -0x400, 0xC00, 3, -0x400, 0xC00, 2, -0x400, 0xC00, -2, -0x400, 0xC00, 1, 0, 512, -3, 0, 512
end table

private table DeathEggRobot_table5
	5, 8, 0, 0x400, -0x1800, 3, 0x400, -0x1800, 2, 0x400, -0x1800, -2, 0x400, -0x1800, 1, 512, -0x600, -3, 512, -0x600
end table

private table DeathEggRobot_table6
	5, 8, 0, 0xC00, -0x1800, 3, 0xC00, -0x1800, 2, 0xC00, -0x1800, -2, 0xC00, -0x1800, 1, 0x400, -0x400, -3, 0x400, -0x400
end table

private table DeathEggRobot_table7
	5, 8, 0, 0x1800, -0xC00, 3, 0x1800, -0xC00, 2, 0x1800, -0xC00, -2, 0x1800, -0xC00, 1, 0x400, -0x400, -3, 0x400, -0x400
end table

private table DeathEggRobot_table8
	5, 8, 0, 0x1800, -0x400, 3, 0x1800, -0x400, 2, 0x1800, -0x400, -2, 0x1800, -0x400, 1, 0x600, -512, -3, 0x600, -512
end table

private table DeathEggRobot_table9
	5, 16, 0, 0, 0x400, 3, 0, 0x400, 2, 0, 0x400, -2, 0, 0x400, 1, 0, 0x400, -3, 0, 0x400
end table

private table DeathEggRobot_table10
	5, 8, 0, 0, -0x800, 3, 0, -0x800, 2, 0, -0x800, -2, 0, -0x800, 1, 0, -0x800, -3, 0, -0x800
end table

private table DeathEggRobot_table11
	6, 32, 1, -0x800, -0x800, 4, -0x800, -0x800, 0, 0, -0x400, 3, 0x400, -0x500, 2, 768, -0x500, -2, -0x400, -0x500, -3, 0, -512
end table

private table DeathEggRobot_table12
	6, 16, 1, -0x1000, -0x400, 4, -0x1000, -0x400, 0, -0x1000, -0x400, 3, -0xC00, -0x500, 2, -0xD00, -0x500, -2, -0x1400, -0x500, -3, -0x800, 0
end table

private table DeathEggRobot_table13
	5, 16, 1, -0x800, 0x400, 4, -0x800, 0x400, 0, -0x800, 0x400, 3, -0x400, 768, 2, -0x500, 768, -2, -0xC00, 768
end table

private table DeathEggRobot_table14
	6, 16, 1, -0x400, 0x1000, 4, -0x800, 0x1000, 0, 0, 0x800, 3, -0x800, 0xA00, 2, -0x600, 0xA00, -2, 0x800, 0xA00, -3, 0, 0x800
end table

private table DeathEggRobot_table15
	6, 32, 1, -512, -512, 0, -0xC00, -0x400, 3, -0x1000, -768, 2, -0xF00, -768, -2, -0x800, -768, -3, -0x1400, -0x600, -1, -0x1800, -0x400
end table

private table DeathEggRobot_table16
	4, 32, -3, -0x800, -0x400, -1, -0x800, -0x400, 3, -0x400, -256, 2, -768, -256, -2, 0x400, -256
end table

private table DeathEggRobot_table17
	6, 16, -3, -0x1000, -0x400, -1, -0x1000, -0x400, 0, -0x1000, -0x400, 3, -0x1400, -0x500, 2, -0x1300, -0x500, -2, -0xC00, -0x500, 1, -0x800, 0
end table

private table DeathEggRobot_table18
	5, 16, -3, -0x800, 0x400, -1, -0x800, 0x400, 0, -0x800, 0x400, 3, -0xC00, 768, 2, -0xB00, 768, -2, -0x400, 768
end table

private table DeathEggRobot_table19
	6, 16, -3, -0x400, 0x1000, -1, -0x800, 0x1000, 0, 0, 0x800, 3, 0x800, 0xA00, 2, 0x600, 0xA00, -2, -0x800, 0xA00, 1, 0, 0x800
end table

private table DeathEggRobot_table20
	6, 32, -3, -512, -512, 0, -0xC00, -0x400, 3, -0x800, -768, 2, -0x900, -768, -2, -0xF00, -768, 1, -0x1400, -0x600, 4, -0x1800, -0x400
end table

private table DeathEggRobot_table21
	4, 32, 1, -0x800, -0x600, 4, -0x800, -0x400, 3, 0x400, -256, 2, 768, -256, -2, -0x400, -256
end table

private table DeathEggRobot_table22
	6, 16, -3, 0, 0x800, -1, 0, 0x800, 0, 0, 0x800, 3, 0, 0x800, 2, 0, 0x800, -2, 0, 0x800, 1, 0, 0x800
end table

function DeathEggRobot_Function101
	temp7 = 0
	GetTableValue(temp6, temp7, temp0)
	temp7++
	while temp6 >= 0
		GetTableValue(temp1, temp7, temp0)
		temp7++
		arrayPos0 = object.entityPos
		arrayPos0 += temp1
		GetTableValue(temp1, temp7, temp0)
		temp7++
		GetTableValue(temp2, temp7, temp0)
		temp7++
		object[arrayPos0].xpos = object.xpos
		if object.direction == FLIP_NONE
			object[arrayPos0].xpos += temp1
		else
			object[arrayPos0].xpos -= temp1
		end if
		object[arrayPos0].ypos = object.ypos
		object[arrayPos0].ypos += temp2
		temp6--
	loop
end function


function DeathEggRobot_Function102
	temp7 = 1
	while temp7 == 1
		temp7 = 0
		temp0 &= 63
		temp1 >>= 6
		switch temp1
		case 1
			if object.animationTimer == 0
				object.frame++
				PlaySfx(SfxName[Crusher], 0)
				GetTableValue(temp0, object.frame, temp6)
				temp1 = temp0
				temp1 &= 192
				if temp1 != 0
					temp7 = 1
				end if
			end if
			break
		case 2
			temp4 = 1
			break
		case 3
			object.frame = 1
			checkResult = 1
			break
		end switch
	loop
end function


function DeathEggRobot_Function103
	GetTableValue(temp5, 0, temp6)
	GetTableValue(temp0, object.frame, temp6)
	temp1 = temp0
	temp4 = 0
	temp1 &= 192
	checkResult = 0
	if temp0 != 0
		CallFunction(DeathEggRobot_Function102)
	end if
	if checkResult == 0
		GetTableValue(temp2, temp0, temp5)
		temp7 = 0
		GetTableValue(temp0, temp7, temp2)
		temp7++
		GetTableValue(temp3, temp7, temp2)
		temp7++
		object.animationTimer++
		if object.animationTimer >= temp3
			object.animationTimer = 0
			object.frame++
		end if
		while temp0 >= 0
			GetTableValue(temp5, temp7, temp2)
			temp7++
			arrayPos0 = object.entityPos
			arrayPos0 += temp5
			GetTableValue(temp1, temp7, temp2)
			temp7++
			temp1 <<= 4
			if object.direction == FLIP_NONE
				if temp4 == 0
					object[arrayPos0].xpos += temp1
				else
					object[arrayPos0].xpos -= temp1
				end if
			else
				if temp4 == 0
					object[arrayPos0].xpos -= temp1
				else
					object[arrayPos0].xpos += temp1
				end if
			end if
			GetTableValue(temp1, temp7, temp2)
			temp7++
			temp1 <<= 4
			if temp4 == 0
				object[arrayPos0].ypos += temp1
			else
				object[arrayPos0].ypos -= temp1
			end if
			temp0--
		loop
	end if
end function


function DeathEggRobot_Function104
	arrayPos0 = object[-7].entityPos
	arrayPos0 += object.value9
	object.value9 += 2
	object.value9 &= 3
	object[arrayPos0].type = TypeName[DER Bomb]
	object[arrayPos0].xpos = object.xpos
	if object.direction == FLIP_NONE
		object[arrayPos0].xpos += 0x380000
		object[arrayPos0].xvel = 0x6000
	else
		object[arrayPos0].xpos -= 0x380000
		object[arrayPos0].xvel = -0x6000
	end if
	object[arrayPos0].ypos = object.ypos
	object[arrayPos0].ypos -= 0x140000
	object[arrayPos0].yvel = -0x80000
	object[arrayPos0].value1 = object[arrayPos0].ypos
	object[arrayPos0].priority = PRIORITY_ACTIVE
	arrayPos0++
	object[arrayPos0].type = TypeName[DER Bomb]
	object[arrayPos0].xpos = object.xpos
	if object.direction == FLIP_NONE
		object[arrayPos0].xpos += 0x380000
		object[arrayPos0].xvel = 0xC000
	else
		object[arrayPos0].xpos -= 0x380000
		object[arrayPos0].xvel = -0xC000
	end if
	object[arrayPos0].ypos = object.ypos
	object[arrayPos0].ypos -= 0x140000
	object[arrayPos0].yvel = -0xA0000
	object[arrayPos0].value1 = object[arrayPos0].ypos
	object[arrayPos0].priority = PRIORITY_ACTIVE
end function


event ObjectMain
	switch object.state
	case 0
		temp0 = stage.curYBoundary2
		temp0 -= screen.ysize
		stage.newYBoundary1 = temp0
		temp0 = object.xpos
		temp0 >>= 16
		temp0 += 68
		stage.newXBoundary2 = temp0
		temp0 -= 512
		stage.newXBoundary1 = temp0
		object.priority = PRIORITY_ACTIVE
		object[+5].type = TypeName[DER Shoulder]
		object[+5].priority = PRIORITY_ACTIVE
		object[+4].type = TypeName[DER Foot]
		object[+4].priority = PRIORITY_ACTIVE
		object[+3].type = TypeName[DER Hand]
		object[+3].priority = PRIORITY_ACTIVE
		object[+2].type = TypeName[DER Arm]
		object[+2].priority = PRIORITY_ACTIVE
		object[+1].type = TypeName[DER Leg]
		object[+1].priority = PRIORITY_ACTIVE
		object[-1].type = TypeName[DER Foot]
		object[-1].priority = PRIORITY_ACTIVE
		object[-2].type = TypeName[DER Hand]
		object[-2].priority = PRIORITY_ACTIVE
		object[-3].type = TypeName[DER Leg]
		object[-3].priority = PRIORITY_ACTIVE
		object.value5 = object.xpos
		object.value5 -= 0xC00000
		object.value6 = 12
		temp0 = DeathEggRobot_table0
		CallFunction(DeathEggRobot_Function101)
		object.frame = 1
		object.value10 = 5
		//SetMusicTrack("FinalBoss.ogg", 4, 1)
		object.state = 1
		break
	case 1
		break
	case 2
		object.value2 -= 0x10000
		if object.value2 <= -0x240000
			object.state = 3
		end if
		break
	case 3
		object.value1 -= 0x7800
		object.rotation -= 4
		if object.rotation <= 0
			object.state = 4
		end if
		break
	case 4
		object.value0++
		if object.value0 == 112
			vs.bossAttack = 0
			ResetObjectEntity(26, TypeName[Music Event], 5, 0, 0)
			object[26].priority = PRIORITY_ACTIVE
		end if
		if object.value0 == 180
			object.value0 = 0
			PlaySfx(SfxName[Large Wall], 0)
			object.value10 = 5
			object.value12 = 4
			object.value13 = 1
			object.state = 5
		end if
		break
	case 5
		object.ypos -= 0x10000
		object.value0++
		if object.value0 == 30
			PlaySfx(SfxName[Large Wall], 0)
		end if
		if object.value0 == 120
			object.value0 = 0
			object[+5].state = 2
			object[+4].state = 2
			object[+3].state = 2
			object[+2].state = 2
			object[+1].state = 2
			object[-1].state = 2
			object[-2].state = 2
			object[-3].state = 2
			object.value13 = 2
			object.state = 6
		end if
		temp0 = DeathEggRobot_table0
		CallFunction(DeathEggRobot_Function101)
		break
	case 6
		object.value0++
		if object.value0 == 32
			object.value0 = 0
			object.state = 7
		end if
		break
	case 7
		object.value0 = 32
		object.value4 = 0
		GetTableValue(object.state, object.value3, DeathEggRobot_table55)
		if object.state == 9
			object.value10 = 5
			object.value12 = 16
			object.value13 = 1
		end if
		object.value3++
		object.value3 &= 3
		break
	case 8
		switch object.value4
		case 0
			object.value0--
			if object.value0 < 0
				object.value4 = 1
			end if
			break
		case 1
			temp6 = DeathEggRobot_table50
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				object.value0 = 64
				object.value4 = 2
			end if
			break
		case 2
			object.value0--
			if object.value0 < 0
				object.value4 = 3
			end if
			break
		case 3
			temp6 = DeathEggRobot_table51
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				object.value0 = 64
				object.state = 7
			end if
			break
		end switch
		break
	case 9
		switch object.value4
		case 0
			object.value0--
			if object.value0 < 0
				object.value4 = 1
			end if
			break
		case 1
			temp6 = DeathEggRobot_table49
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				object.value0 = 128
				PlaySfx(SfxName[Thruster], 0)
				object.value4 = 2
			end if
			break
		case 2
			object.value0--
			if object.value0 < 0
				object.value4 = 3
			else
				object.ypos -= 0x20000
				temp0 = oscillation
				temp0 &= 31
				if temp0 == 0
					PlaySfx(SfxName[Thruster], 0)
				end if
				temp0 = DeathEggRobot_table0
				CallFunction(DeathEggRobot_Function101)
			end if
			break
		case 3
			object.value0--
			if object.value0 < 0
				object.value0 = 0
				object.value4 = 4
				object[+6].type = TypeName[DER Target]
				object[+6].xpos = object[0].xpos
				object[+6].ypos = object[0].ypos
			end if
			break
		case 4
			if object.value0 != 0
				if object.xpos < object.value5
					object.direction = FLIP_X
				else
					object.direction = FLIP_NONE
				end if
				object[+5].direction = object.direction
				object[+4].direction = object.direction
				object[+3].direction = object.direction
				object[+2].direction = object.direction
				object[+1].direction = object.direction
				object[-1].direction = object.direction
				object[-2].direction = object.direction
				object[-3].direction = object.direction
				object.value0 = 32
				temp0 = DeathEggRobot_table0
				CallFunction(DeathEggRobot_Function101)
				object.value4 = 5
			end if
			break
		case 5
			object.value0--
			if object.value0 < 0
				object.value0 = 64
				PlaySfx(SfxName[Ledge Break], 0)
				object.value14 = 64
				object.value13 = 2
				object.value4 = 6
			else
				object.ypos += 0x80000
				temp0 = DeathEggRobot_table0
				CallFunction(DeathEggRobot_Function101)
			end if
			break
		case 6
			temp6 = DeathEggRobot_table48
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				temp0 = DeathEggRobot_table0
				CallFunction(DeathEggRobot_Function101)
				temp0 = 0
				if object.direction == FLIP_NONE
					if object[0].xpos > object.xpos
						temp0 = 1
					end if
				else
					if object[0].xpos < object.xpos
						temp0 = 1
					end if
				end if
				if temp0 == 0
					object.state = 7
				else
					object.value0 = 96
					object.value4 = 7
					CallFunction(DeathEggRobot_Function104)
				end if
			end if
			break
		case 7
			object.value0--
			if object.value0 < 0
				object.state = 7
			end if
			break
		end switch
		break
	case 10
		switch object.value4
		case 0
			object.value0--
			if object.value0 < 0
				object.value4 = 1
			end if
			break
		case 1
			temp6 = DeathEggRobot_table46
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				temp0 = 0
				if object.direction == FLIP_NONE
					if object[0].xpos > object.xpos
						temp0 = 1
					end if
				else
					if object[0].xpos < object.xpos
						temp0 = 1
					end if
				end if
				if temp0 == 0
					object.value0 = 64
					object[+3].state = 3
					object[+3].value0 = 16
					object[+3].value1 = object[+3].ypos
					object.value4 = 2
				else
					object.value0 = 32
					object.value4 = 4
					CallFunction(DeathEggRobot_Function104)
				end if
			end if
			break
		case 2
			object.value0--
			if object.value0 < 0
				object.value4 = 3
			end if
			break
		case 3
			object.value0--
			if object.value0 < 0
				object.value0 = 64
				object[-2].state = 3
				object[-2].value0 = 16
				object[-2].value1 = object[-2].ypos
				object.value4 = 4
			end if
			break
		case 4
			object.value0--
			if object.value0 < 0
				object.value4 = 5
			end if
			break
		case 5
			temp6 = DeathEggRobot_table47
			CallFunction(DeathEggRobot_Function103)
			if checkResult == 1
				object.state = 7
			end if
			break
		end switch
		break
	case 11
		object.value0++
		if object.value0 == 120
			object.value0 = 0
			object.value8 = 0
			object.state++
			options.touchControls = 0
			object[0].controlMode = -1
			object[0].jumpPress = 0
			object[0].jumpHold = 0
			object[0].up = 0
			object[0].down = 0
			object[0].left = 0
			object[0].right = 1
			stage.deathBoundary = 0x7FFF0000
			temp0 = tileLayer[0].xsize
			temp0 <<= 7
			stage.newXBoundary2 = temp0
		end if
		object.ypos += object.yvel
		object.yvel += 0x3800
		ObjectTileCollision(CSIDE_FLOOR, 0, 36, 0)
		if checkResult == 1
			object.yvel >>= 2
			FlipSign(object.yvel)
			if object.yvel > -0x10000
				object.yvel = 0
			end if
		end if
		break
	case 12
		object.value0++
		if object.value0 == 30
			object.value14 = 0xFFFF
		end if
		temp0 = object.value14
		temp0 %= 40
		if temp0 == 8
			PlaySfx(SfxName[Rumble], 0)
		end if
		object[0].right = 1
		if object[0].xpos > object[+7].xpos
			object.value0 = -15
			object.state = 13
			if object.value14 == 0
				object.value14 = 0xFFFF
			end if
		end if
		temp0 = object.value15
		arrayPos0 = object[+8].entityPos
		arrayPos0 += object.value15
		temp1 = object[arrayPos0].xpos
		if object[0].xpos > temp1
			object.value15++
			temp0++
			arrayPos0++
		end if
		while temp0 < 7
			object[arrayPos0].state = 1
			arrayPos0++
			temp0++
		end if
		break
	case 13
		temp0 = object.value14
		temp0 %= 40
		if temp0 == 8
			PlaySfx(SfxName[Rumble], 0)
		end if
		Rand(temp0, 96)
		temp0 -= 48
		temp0 <<= 16
		temp0 += object[0].xpos
		temp0 -= 0x400000
		Rand(temp1, 96)
		temp1 -= 48
		temp1 <<= 16
		temp1 += object[0].ypos
		CreateTempObject(TypeName[Explosion], 0, temp0, temp1)
		object[tempObjectPos].drawOrder = 5
		temp0 = oscillation
		temp0 &= 3
		if temp0 == 0
			PlaySfx(SfxName[Explosion], 0)
		end if
		object.value0++
		if object.propertyValue == 0
			switch object.value0
			case 120
			case 180
			case 240
				PlaySfx(SfxName[Large Explosion], 0)
				break
			case 270
				object.state = 14
				break
			end switch
		else
			if object.value0 > 140
				PlaySfx(SfxName[Large Explosion], 0)
				ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)
			end if
		end if
		object[0].right = 1
		temp0 = object.value15
		arrayPos0 = object[+8].entityPos
		arrayPos0 += object.value15
		temp1 = object[arrayPos0].xpos
		if object[0].xpos > temp1
			object.value15++
			temp0++
			arrayPos0++
		end if
		while temp0 < 7
			object[arrayPos0].state = 1
			arrayPos0++
			temp0++
		end if
	case 14
		if object.value0 >= 120
			music.volume--
			object.value16 += 2
			if object.propertyValue == 0
				SetScreenFade(255, 255, 255, object.value16)
			end if
			if object.value16 >= 768
				if stage.debugMode == 0
					if options.stageSelectFlag == 0
						CallNativeFunction2(SetLeaderboard, 22, player.score)
					end if
				end if
				if options.gameMode == 1
					arrayPos1 = options.saveSlot
					arrayPos1 <<= 3
					arrayPos1 += 4
					saveRAM[arrayPos1] = 22
					WriteSaveRAM()
				end if
				stage.activeList = PRESENTATION_STAGE
				stage.listPos = 1
				LoadStage()
			end if
		end if
		break
	end switch
	if object.state > 5
		if object.value6 != 0
			if object.value7 > 0
				object.value7--
				GetBit(temp0, object.value7, 0)
				if temp0 == 1
					SetPaletteEntry(0, 192, 0xE0E0E0)
				else
					SetPaletteEntry(0, 192, 0)
				end if
			end if
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				if object.value7 == 0
					BoxCollisionTest(C_TOUCH, object.entityPos, -32, -60, 32, 32, currentPlayer, object[currentPlayer].value40, object[currentPlayer].value38, object[currentPlayer].value41, object[currentPlayer].value39)
					if checkResult == 1
						CallFunction(PlayerObject_CheckHit)
						if checkResult == 1
							object.value6--
							if object.value6 == 0
								player.score += 1000
								object.value8 = 1
								object.state = 11
								stage.timeEnabled = false
								object.value0 = 0
								object[+5].state = 1
								object[+5].xvel = 0x20000
								object[+5].yvel = -0x40000
								object[+4].state = 1
								object[+4].xvel = -0x10000
								object[+4].yvel = -0x10000
								object[+3].state = 1
								object[+3].xvel = 0x30000
								object[+3].yvel = -0x30000
								object[+2].state = 1
								object[+2].xvel = -0x10000
								object[+2].yvel = -0x40000
								object[+1].state = 1
								object[+1].xvel = 0x18000
								object[+1].yvel = -0x20000
								object[-1].state = 1
								object[-1].xvel = -0x20000
								object[-1].yvel = -0x30000
								object[-2].state = 1
								object[-2].xvel = 0
								object[-2].yvel = -0x40000
								object[-3].state = 1
								object[-3].xvel = 0x10000
								object[-3].yvel = -0x30000
								object.value13 = 3
							else
								object.value7 = 60
								PlaySfx(SfxName[Boss Hit], 0)
							end if
						end if
					else
						if object.direction == FLIP_NONE
							BoxCollisionTest(C_TOUCH, object.entityPos, 48, 16, 64, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
						else
							BoxCollisionTest(C_TOUCH, object.entityPos, -64, 16, -48, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
						end if
						if checkResult == 1
							CallFunction(PlayerObject_FireHit)
						end if
					end if
				end if
			next
		end if
	end if
	if object.state <= 11
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			temp0 = object[currentPlayer].collisionRight
			temp0 <<= 16
			temp0 += object[currentPlayer].xpos
			temp1 = stage.curXBoundary2
			temp1 <<= 16
			if temp0 > temp1
				object[currentPlayer].xvel = 0
				object[currentPlayer].speed = 0
				object[currentPlayer].xpos = temp1
				temp0 = object[currentPlayer].collisionRight
				temp0 <<= 16
				object[currentPlayer].xpos -= temp0
			end if
		next
	end if
	if object.value8 == 1
		temp0 = oscillation
		temp0 &= 7
		if temp0 == 0
			Rand(temp0, 48)
			temp0 -= 24
			temp0 <<= 16
			temp0 += object.xpos
			Rand(temp1, 48)
			temp1 -= 24
			temp1 <<= 16
			temp1 += object.ypos
			CreateTempObject(TypeName[Explosion], 0, temp0, temp1)
			object[tempObjectPos].drawOrder = 5
			PlaySfx(SfxName[Explosion], 0)
		end if
	end if
	if object.value14 > 0
		object.value14--
		temp0 = object.value14
		temp0 &= 7
		if temp0 == 0
			screen.shakeX = 1
		end if
		temp0 = object.value14
		temp0 &= 3
		if temp0 == 0
			screen.shakeY = 2
		end if
	end if
	switch object.value13
	case 0
		object.value10 -= 4
		object.value10 ^= 1
		object.value10 += 4
		break
	case 1
		object.value11 += 2
		if object.value11 >= object.value12
			object.value11 = 0
			object.value10 -= 5
			object.value10 ^= 1
			object.value10 += 5
			if object.value12 > 4
				object.value12--
			end if
		end if
		break
	case 2
		object.value11 += 2
		if object.value11 >= object.value12
			object.value11 = 0
			object.value10 -= 5
			object.value10 ^= 1
			object.value10 += 5
			if object.value12 < 16
				object.value12++
				if object.value12 == 16
					object.value10 = 5
					object.value13 = 0
				end if
			end if
		end if
		break
	case 3
		object.value10 = 4
		break
	end switch
end event


event ObjectDraw
	temp0 = object.xpos
	if object.direction == FLIP_NONE
		temp0 += object.value1
	else
		temp0 -= object.value1
	end if
	temp1 = object.ypos
	temp1 += object.value2
	DrawSpriteFX(2, FX_ROTATE, temp0, temp1)
	DrawSpriteFX(3, FX_FLIP, object.xpos, object.ypos)
	DrawSpriteFX(object.value10, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone12")
	if checkResult == 1
		LoadSpriteSheet("DEZ/Objects.gif")
		SpriteFrame(12, -16, 23, 32, 487, 150)
		SpriteFrame(-20, -13, 54, 29, 430, 125)
		SpriteFrame(-32, -24, 71, 24, 414, 158)
		SpriteFrame(-44, -36, 112, 72, 399, 183)
		SpriteFrame(0, 0, 1, 1, 495, 106)
		SpriteFrame(48, 12, 16, 16, 495, 108)
		SpriteFrame(48, 12, 16, 24, 495, 83)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(12, -16, 23, 32, 999, 150)
		SpriteFrame(-20, -13, 54, 29, 942, 125)
		SpriteFrame(-32, -24, 71, 24, 926, 158)
		SpriteFrame(-44, -36, 112, 72, 911, 183)
		SpriteFrame(0, 0, 1, 1, 1007, 106)
		SpriteFrame(48, 12, 16, 16, 1007, 108)
		SpriteFrame(48, 12, 16, 24, 1007, 83)
	end if
	foreach (TypeName[Death Egg Robot], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].rotation = 128
		object[arrayPos0].value1 = 0xB0000
		object[arrayPos0].value2 = -0x40000
	next
	SetTableValue(DeathEggRobot_table52, 0, DeathEggRobot_table46)
	
	SetTableValue(DeathEggRobot_table52, 0, DeathEggRobot_table47)
	
	SetTableValue(DeathEggRobot_table52, 0, DeathEggRobot_table48)
	
	SetTableValue(DeathEggRobot_table53, 0, DeathEggRobot_table49)
	
	SetTableValue(DeathEggRobot_table54, 0, DeathEggRobot_table50)
	
	SetTableValue(DeathEggRobot_table54, 0, DeathEggRobot_table51)
	
	SetTableValue(DeathEggRobot_table1, 0, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table2, 1, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table3, 2, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table4, 3, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table60, 4, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table5, 5, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table6, 6, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table7, 7, DeathEggRobot_table52)
	SetTableValue(DeathEggRobot_table8, 8, DeathEggRobot_table52)
	
	SetTableValue(DeathEggRobot_table9, 0, DeathEggRobot_table53)
	SetTableValue(DeathEggRobot_table56, 1, DeathEggRobot_table53)
	SetTableValue(DeathEggRobot_table10, 2, DeathEggRobot_table53)
	
	SetTableValue(DeathEggRobot_table11, 0, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table12, 1, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table13, 2, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table14, 3, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table15, 4, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table16, 5, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table17, 6, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table18, 7, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table19, 8, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table20, 9, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table21, 10, DeathEggRobot_table54)
	SetTableValue(DeathEggRobot_table22, 11, DeathEggRobot_table54)
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
